from textual.app import App, ComposeResult
from textual.containers import Vertical, Horizontal
from textual.widgets import Input, Static, Button

class DouyinExtractor(App):
    CSS_PATH = "style.tcss"
    
    def compose(self) -> ComposeResult:
        with Horizontal(id="top-container"):
            yield Input(placeholder="粘贴抖音分享链接", id="url-input")
            yield Button("提取", id="extract-btn")
        with Vertical(id="result-container"):
            yield Static("等待输入...", id="result-text")
            yield Button("复制文案", id="copy-btn")
    
    def on_input_submitted(self, event: Input.Submitted):
        if event.input.id == "url-input":
            self.run_extract(event.value)
    
    def on_button_pressed(self, event: Button.Pressed):
        if event.button.id == "extract-btn":
            self.run_extract(self.query_one("#url-input").value)
        elif event.button.id == "copy-btn":
            self.app.copy_to_clipboard(self.query_one("#result-text").renderable)
            self.notify("已成功复制到剪贴板")
    
    def run_extract(self, url: str):
        # 测试用提取函数
        sample_text = "这是示例文案：欢迎来到我的抖音，点击关注观看更多精彩内容！"
        self.query_one("#result-text").update(sample_text)

if __name__ == "__main__":
    app = DouyinExtractor()
    app.run()